<!--
* description: 网点安全库存周期维护
* author: ligy
* createdDate: 2021-3-4
-->

<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="true"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
      :callback-obj="callbackObj"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import api from "@/api/pa/apiBranchWarehouse";
import Vue from "vue";
import request from "@/utils/request";
export default {
  name: "SparePartsSoldOut",

  components: {
    OneTableTemplate,
    // Edit: () => import('./edit')
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      editRowData: {},
      selection: [],
      // 网格查询API配置对象
      apiConfig: api.queryDlrSafetyStockBaseInfo,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "",
          size: "small",
          parentFileds: "disabled:table",
          disabled: true,
          clickEvent: () => this.save(),
          text: "保存", // 新增
          name: "adopt",
          position: "left",
        },
      ],
      callbackObj: {
        // 手动勾选时
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection;
        },
        onCheckSelectChange: (selection) => {
          this.onCheckSelectChange1(selection);
        },
      },
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "dlrId",
                label: "所属专营ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "updateControlId",
                label: "并发id",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "dlrCode",
                label: "网点编码",
              },
              {
                prop: "dlrShortName",
                label: "网点名称",
              },

              {
                prop: "stockcycle",
                label: "安全库存周期+",
                isComponent: true,
                comps: [
                  {
                    compKey: "compKey5" + this.$utils.generateId(),
                    codeField: "stockcycle",
                    component: () => import("@/components/org/commonInput"),
                    change: (val, comType, row) =>
                      this.changeRow(val, comType, row),
                    type: "inputText",
                  },
                ],
              },
              {
                prop: "ordercycle",
                label: "订货日历周期+",
              },
              {
                prop: "remark",
                label: "备注+",
                isComponent: true,
                comps: [
                  {
                    compKey: "compKey5" + this.$utils.generateId(),
                    codeField: "remark",
                    component: () => import("@/components/org/commonInput"),
                    type: "inputText",
                  },
                ],
              },
            ],
      // 表单查询数据
      formField: this.$utils.getFormField(
        this,
        {},
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },

  mounted() {
    // 列表查询
    this.queryTable(1);
  },

  methods: {
    changeRow(val, comType, row) {
      row.ordercycle = val + "/30";
    },
    onCheckSelectChange1(selection) {
      var btn1 = this.tableButtons[0];
      const isCheck = selection && selection.length > 0;
      btn1.disabled = !isCheck;
      this.selectiondata = selection;
    },
    // 保存
    save() {
      request({
        url: api.saveDlrPartWarehouse.APIUrl,
        method: "post",
        data: this.selectiondata,
      }).then((res) => {
        if (res.result == "1") {
          this.$message.success(res.msg);
          this.queryTable(1);
        } else {
          this.$message.warning(res.msg);
        }
      });
    },
  },
};
</script>
<style lang='scss' scoped>
.span {
  float: right;
}
</style>